package com.ioffice.export.excel;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;

public class SheetUtils {

	/**
	 * 获取单元格样式水平居中
	 * @param wb
	 * @return
	 */
	public static HSSFCellStyle getAlignmentCenterStyle(HSSFWorkbook wb){
		HSSFCellStyle style=wb.createCellStyle();
		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
		return style;
	}
	/**
	 * 获取单元格样式水平居右
	 * @param wb
	 * @return
	 */
	public static HSSFCellStyle getAlignmentRightStyle(HSSFWorkbook wb){
		HSSFCellStyle style=wb.createCellStyle();
		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
		style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);//水平居右
		return style;
	}
	/**
	 * 获取单元格样式水平居左
	 * @param wb
	 * @return
	 */
	public static HSSFCellStyle getAlignmentLeftStyle(HSSFWorkbook wb){
		HSSFCellStyle style=wb.createCellStyle();
		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
		style.setAlignment(HSSFCellStyle.ALIGN_LEFT);//水平左
		return style;
	}
	
	
	/**
	 * 合并单元格
	 * @param sheet
	 * @param x 表示的是第几行
	 * @param y 表示的是第几列
	 * @param xspan
	 * @param yspan
	 */
	public static void mergerSheetCell(Sheet  sheet,int x,int y,int xspan,int yspan){
		if(xspan>0&&yspan>0)
			sheet.addMergedRegion(new CellRangeAddress(y,y+yspan-1,x,x+xspan-1));
		
	} 
	
}
